import request from './index'

// 获取支付确认列表
export function getPaymentList(params) {
  const { perspective = 'seller', status, page = 1, pageSize = 20 } = params
  
  // 转换参数格式以匹配后端API
  const apiParams = {
    start: (page - 1) * pageSize,
    count: pageSize,
    status: status,
    perspective: perspective
  }
  
  // 根据视角选择不同的API端点，与微信小程序保持一致
  const url = perspective === 'seller' 
    ? 'order/vip-payment-confirm' 
    : 'order/vip-payment-buyer'
  
  return request({
    url: url,
    method: 'get',
    params: apiParams
  })
}

// 获取支付确认统计
export function getPaymentStats(params) {
  const { perspective = 'seller' } = params
  
  // 根据视角选择不同的API端点，与微信小程序保持一致
  const url = perspective === 'seller' 
    ? 'order/vip-payment-stats' 
    : 'order/vip-payment-buyer-stats'
  
  return request({
    url: url,
    method: 'get'
  })
}

// 确认支付
export function confirmPayment(paymentId, data) {
  return request({
    url: `order/vip-confirm-payment/${paymentId}`,
    method: 'post',
    data: data
  })
}

// 拒绝支付
export function rejectPayment(paymentId, data) {
  return request({
    url: `order/vip-reject-payment/${paymentId}`,
    method: 'post',
    data: data
  })
}

// 重新上传支付凭证（买方被拒绝后重新上传）
export function reuploadPaymentProof(paymentId, data) {
  return request({
    url: `order/vip-reupload-payment-proof/${paymentId}`,
    method: 'post',
    data: data
  })
}

// 获取支付详情
export function getPaymentDetail(id, params = {}) {
  const { perspective = 'seller' } = params
  return request({
    url: `order/vip-payment-detail/${id}`,
    method: 'get',
    params: { perspective }
  })
}

// 上传支付凭证
export function uploadPaymentProof(data) {
  return request({
    url: 'payment-confirm/upload-proof',
    method: 'post',
    data: data
  })
}

// 获取我的二维码
export function getMyQRCode() {
  return request({
    url: 'payment-confirm/my-qrcode',
    method: 'get'
  })
}

// 生成二维码
export function generateQRCode(data) {
  return request({
    url: 'payment-confirm/generate-qrcode',
    method: 'post',
    data: data
  })
} 